#-*- coding: utf-8 -*-
from django.conf import settings
from django.db import models

class Account(models.Model):
    username = models.CharField('帐号', max_length=32, unique=True)
    password = models.CharField('密码', max_length=64)
    create_time = models.DateTimeField('创建时间', auto_now_add=True)


class Label(models.Model):
    name = models.CharField('标签名', max_length=20, unique=True)
    create_time = models.DateTimeField('创建时间', auto_now_add=True)


class UserLabel(models.Model):
    account = models.ForeignKey('account.Account', on_delete=models.CASCADE)
    label = models.ForeignKey('account.Label', on_delete=models.CASCADE)


class Image(models.Model):
    label = models.ForeignKey('account.Label', on_delete=models.CASCADE)
    key = models.CharField('键', max_length=128, unique=True)
    create_time = models.DateTimeField('创建时间', auto_now_add=True)

    @property
    def url(self):
        return "{0}{1}".format(settings.QINIU['url'], self.key)
